//
//  WBFristPageTableViewCell.swift
//  weibo
//
//  Created by  郭航 on 16/6/27.
//  Copyright © 2016年 郭航. All rights reserved.
//

import UIKit
import SnapKit

class WBFristPageTableViewCell: UITableViewCell {
    
    var dataModel: WBFristPageDataModel? {
        didSet {
            headView.dataModel = dataModel
            tabbarToolView.dataModel = dataModel
            
            if dataModel?.retweeted_status != nil {
                retweetedView.dataModel = dataModel
                retweetedView.hidden = false
                
                tabbarToolTopConstraint?.uninstall()
                tabbarToolView.snp_makeConstraints { (make) in
                    tabbarToolTopConstraint = make.top.equalTo(retweetedView.snp_bottom).constraint
                }
            } else {
                retweetedView.hidden = true
                
                tabbarToolTopConstraint?.uninstall()
                tabbarToolView.snp_makeConstraints { (make) in
                    tabbarToolTopConstraint = make.top.equalTo(headView.snp_bottom).constraint
                }
            }
        }
    }
    
    private var tabbarToolTopConstraint: Constraint?
    
    private lazy var headView: WBFristPageCellHeadView = WBFristPageCellHeadView()
    
    private lazy var retweetedView: WBFristPageRetweetedView = WBFristPageRetweetedView()
    
    private lazy var tabbarToolView: WBFristPageTabbarToolView = WBFristPageTabbarToolView()
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        backgroundColor = RGB(red: 237, green: 237, blue: 237)

        contentView.addSubview(headView)
        
        headView.snp_makeConstraints { (make) in
            make.leading.trailing.equalTo(contentView)
            make.top.equalTo(contentView).offset(8)
        }
        
        contentView.addSubview(retweetedView)
        
        retweetedView.snp_makeConstraints { (make) in
            make.leading.trailing.equalTo(contentView)
            make.top.equalTo(headView.snp_bottom)
        }
        
        contentView.addSubview(tabbarToolView)
        
        tabbarToolView.snp_makeConstraints { (make) in
            tabbarToolTopConstraint = make.top.equalTo(headView.snp_bottom).constraint
            make.leading.trailing.equalTo(contentView)
            make.height.equalTo(35)
        }
        
        contentView.snp_makeConstraints { (make) in
            make.top.leading.trailing.equalTo(self)
            make.bottom.equalTo(tabbarToolView)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
